import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'gamePage.dart';
class UpdatePage extends StatefulWidget{
  @override
  _UpdatePage createState() {
    // TODO: implement createState
    return _UpdatePage();
  }
}
class _UpdatePage extends State<UpdatePage> with AutomaticKeepAliveClientMixin{
  ScrollController controller;
  bool showTitle;
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    showTitle=false;
    controller=ScrollController();
    controller.addListener((){
      setState(() {
        showTitle=controller.position.pixels>=40;
      });
    });

  }
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      appBar: AppBar(
        title: showTitle?Text("更新"):Text(""),
        elevation: showTitle==true?1:0,
      ),
      body: Container(
        color: Colors.white,
        child: CustomScrollView(
          controller: controller,
          slivers: <Widget>[
            SliverToBoxAdapter(
              child: titleWidget("更新"),
            ),
            SliverToBoxAdapter(
              child: recentUpdate(
                title: "等待中",
              ),
            ),
            SliverList(
              delegate: SliverChildBuilderDelegate(
                (context,index){
                  return UpdateItem();
                },
                childCount: 5
              ),
            ),
            SliverToBoxAdapter(
              child: recentUpdate(
                title: "近期更新",
              ),
            ),
            SliverList(
              delegate: SliverChildBuilderDelegate(
                (context,index){
                  return UpdateItem();
                },
                childCount: 66
              ),
            )
          ],
        ),
      ),
    );
  }

  @override
  // TODO: implement wantKeepAlive
  bool get wantKeepAlive => true;
}
//更新种类，分为近期更新和正在更新
class recentUpdate extends StatelessWidget{
  String title;
  recentUpdate({this.title});
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Container(
      margin: EdgeInsets.only(left: 20,top: 10,right: 40),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: <Widget>[
          Text("${title}",style: TextStyle(
            fontSize: 20,
            fontWeight: FontWeight.w600,
          ),
          ),
          Offstage(
            offstage: title=="等待中"?false:true,
            child: GestureDetector(
              child: Text("全部更新",style: TextStyle(color: Colors.lightBlue),),
              onTap: (){},
            ),
          )
        ],
      )
    );
  }
}

//单个更新item
class UpdateItem extends StatelessWidget{
  String icon;
  String title;
  String desc;
  UpdateItem({this.title,this.desc,this.icon});
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Container(
      margin: EdgeInsets.only(top: 10,bottom: 10,right: 30),
      child: Column(
        children: <Widget>[
          //上部分icon title  按钮 
          Row(
            children: <Widget>[
              //icon
              Container(
                margin: EdgeInsets.only(left: 20,right: 10),
                child: ClipRRect(
                  borderRadius: BorderRadius.circular(10),
                  child: Image.asset("images/ban1.png",width:60,height: 60,fit: BoxFit.cover,),
                ),
              ),
              //title和日期
              Expanded(
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: <Widget>[
                    Text("爱奇艺-破冰行动全网独播",style: TextStyle(
                      fontSize: 16,
                    ),
                    maxLines: 1,
                    overflow: TextOverflow.ellipsis,
                    ),
                    Text("今天",style: TextStyle(
                      fontSize: 12,
                      color: Colors.grey
                    ),)
                  ],
                ),
              ),
              //按钮
              Container(
                padding: EdgeInsets.only(left: 20,top: 2,right: 20,bottom: 2),
                decoration: BoxDecoration(
                  borderRadius: BorderRadius.circular(20),
                  color: Color.fromRGBO(241, 240, 247, 1)
                ),
                child: GestureDetector(
                  child: Text("打开",style: TextStyle(color: Colors.blue,fontSize: 16),),
                  onTap: (){},
                )
              )
            ],
          ),
          //下部分描述
          Container(
            decoration: BoxDecoration(
              border: Border(
                bottom: BorderSide(
                  width: 0.3,
                  color: Colors.grey
                )
              )
            ),
            margin: EdgeInsets.only(top: 15),
            padding: EdgeInsets.only(left: 20,right: 20,bottom: 10),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: <Widget>[
                Text("【大剧热综不打烊】《乐队的夏天》全网独播，用音乐点燃一夏；《动物管理局》惊喜上线，全军出击让你“笑出原形”\n【VIP会员体系重磅升级】",
            style: TextStyle(fontSize: 14),),
                Container(
                  margin: EdgeInsets.only(top: 10),
                  child: Text("版本 10.0.5·170.1MB",style: TextStyle(fontSize: 16,color: Colors.grey),),
                )
              ],
            )

          )
        ],
      ),
    );
  }
}